﻿@using General.Entities.ViewData.Template
@{
    Layout = "~/Views/Shared/_LayoutAdminPage.cshtml";
    var templateList = (List<TemplateModel>)ViewBag.TemplateList;
}

<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body text-danger">
            请将模板文件夹放入template目录下
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 表格工具栏 -->
            <form class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">选择模板:</label>
                        <div class="layui-input-inline">
                            <select name="templateSelect">
                                @foreach (var item in templateList)
                                {
                                    if (item.isChecked)
                                    {
                                        <option selected value="@item.name">@item.name</option>
                                    }
                                    else
                                    {
                                        <option value="@item.name">@item.name</option>
                                    }
                                }
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        &emsp;
                        <button class="layui-btn icon-btn" lay-filter="selectTemplateBtn" lay-submit>
                            确定
                        </button>
                    </div>
                </div>
            </form>
            <!-- 数据表格 -->
            <table id="templateTable" lay-filter="templateTable"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="templateTbBar">
    <a class="layui-btn layui-btn-primary layui-btn-sm" lay-event="edit"><i class="layui-icon">&#xe6b2;</i>修改</a>
</script>

<script>
    layui.use(['layer', 'form', 'table', 'util', 'admin', 'xmSelect' , 'notice'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var xmSelect = layui.xmSelect;
        var notice = layui.notice;



        /* 渲染表格 */
        var insTb = table.render({
            elem: '#templateTable',
            url: '/api/admin/Template/GetTemplatePages',
            page: true,
            cellMinWidth: 100,
            cols: [[
                { type: 'numbers', title: '#' },
                { field: 'name', title: '文件名' },
                { field: 'remark', title: '备注' },
                { title: '操作', toolbar: '#templateTbBar', align: 'center', minWidth: 200 }
            ]]
        });



        form.on('submit(selectTemplateBtn)', function (data) {
            var loadIndex = layer.load(2);
            $.post('/api/admin/template/SetTemplateName', data.field, function (res) {
                layer.close(loadIndex);
                if (res.code == 1) {
                    layer.msg(res.message, { icon: 1 });
                } else {
                    layer.msg(res.message, { icon: 2 });
                }
            }, 'json');
            return false;
        });

        /* 表格工具条点击事件 */
        table.on('tool(templateTable)', function (obj) {
            if (obj.event === 'edit') { // 修改
                showEditModel(obj.data);
            }
        });

        function showEditModel(mData) {
            parent.layer.open({
                title: '在线代码编辑器 - ' + mData.name,
                shadeClose: true,
                area: ['1100px', '700px'],
                maxmin: true,
                resize: true,
                type: 2,
                content: '/api/admin/Template/ShowCodeEditer?fileName=' + mData.name,
                success: function (layero, index) {
                    
                }
            });
           // parent.layui.admin.open({
           //    type: 2,
           //     title: '在线代码编辑器 - ' + mData.name,
           //     url: '/api/admin/Template/ShowCodeEditer?fileName=' + mData.name,
           //     shade: 0,
           //     maxmin: true,
           //     resize: true,
           //     area: ['1100px', '700px'],
           //     tpl: true,
           //     success: function (layero) {
                    
           //     }
           //});
        }
        
    });</script>